package com.haibei.activity.market;

import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;

import com.common.BaseActivity;
import com.haibei.R;
import com.haibei.view.web.PageProgressView;
import com.haibei.view.web.WebActionCallBack;
import com.haibei.view.web.WebPageClient;
import com.haibei.view.web.WuyouWebview;

public class ShopingActivity extends BaseActivity implements OnClickListener, WebActionCallBack, OnTouchListener,
		android.view.GestureDetector.OnGestureListener {

	private WuyouWebview mwv;
	private PageProgressView mProgressBar;
	private static final int PROGRESS_MAX = 100;
	private static final int FLING_MIN_DISTANCE = 50;
	private static final int FLING_MIN_VELOCITY = 100;
	private boolean mInLoad;
	private GestureDetector mGestureDetector;
	private String url = "http://a.m.tmall.com/i23607208139.htm?rn=8L78bGOB2-fRRQvcKE7oLIeuoEC5-xop11KO-sMV3&sid=014ffe28bb89b965&abtest=0***";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initView();
	}

	@Override
	public void initView() {
		setContentView(R.layout.activity_shopping);
		mwv = (WuyouWebview) findViewById(R.id.webView);
		mProgressBar = (PageProgressView) findViewById(R.id.wuyou_progressbar);
		new WebPageClient(mwv, this, this);// 为webview设置webviewclient和webviewchromeclient
		mwv.loadUrl(url);
		mwv.setOnTouchListener(this);
		// ==============
		mGestureDetector = new GestureDetector(this);
		findViewById(R.id.main_back_image).setOnClickListener(this);
		findViewById(R.id.main_forword_image).setOnClickListener(this);
		findViewById(R.id.main_gohome_view).setOnClickListener(this);

	}

	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}

	public static String getUrl(String numId) {
		String url = "http://a.m.taobao.com/i" + numId + ".htm";
		return url;
	}

	@Override
	public void setWebProgress(int newProgress) {
		if (newProgress >= PROGRESS_MAX) {
			mProgressBar.setProgress(PageProgressView.MAX_PROGRESS);
			mProgressBar.setVisibility(View.GONE);
			mInLoad = false;
		} else {
			if (!mInLoad) {
				mProgressBar.setVisibility(View.VISIBLE);
				mInLoad = true;
			}
			mProgressBar.setProgress(newProgress * PageProgressView.MAX_PROGRESS / PROGRESS_MAX);
		}

	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		return false;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		return false;
	}

	@Override
	public void jsActionCallBack(String actionFlag, Object obj) {
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.main_back_image:
			mwv.goBack();
			break;
		case R.id.main_forword_image:
			mwv.goForward();
			break;
		// case R.id.title_left_btn:
		// backFinish();
		// break;
		default:
			break;
		}

	}

	@Override
	public void backFinish() {
		super.backFinish();
	}

	@Override
	public void onShowPress(MotionEvent e) {

	}
}
